package net.zigin.nhi.could.waste.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.zigin.nhi.could.waste.dto.MaterialApplyDto;
import net.zigin.nhi.could.waste.service.MaterialApplyService;

import net.zigin.nhi.could.waste.vo.JsonForResult;
import net.zigin.nhi.could.waste.vo.MaterialApplyVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * MaterialApply控制器类
 * @ClassName: MaterialApplyController
 * @author mgw1986
 * @date 2021-9-12 21:08:10
 * @version V1.0
 */
@Api(tags = "耗材申请管理")
@RestController
@RequestMapping("/materialApply")
public class MaterialApplyController extends BaseController {
	@Autowired
	private MaterialApplyService materialApplyService;

	/**
	 * 新增编辑耗材申请
	 *
	 * @param materialApplyDto 耗材申请信息
	 * @return 耗材申请ID
	 */
	@ApiOperation("新增编辑耗材申请")
	@ApiImplicitParam(name = "materialApplyDto", value = "耗材申请信息", required = true, dataType = "MaterialApplyDto")
	@PostMapping("/save")
	public JsonForResult<String> sava(@RequestBody MaterialApplyDto materialApplyDto) {
		String id = materialApplyService.saveOrUpdate(materialApplyDto);
		return JsonForResult.<String>builder().data(id).success(true).build();
	}

	/**
	 * 耗材申请列表
	 *
	 * @param materialApplyDto 耗材申请信息
	 * @return 耗材申请列表
	 */
	@ApiOperation("耗材申请列表")
	@ApiImplicitParam(name = "materialApplyDto", value = "耗材申请信息", required = true, dataType = "MaterialApplyDto")
	@PostMapping("/getList")
	public JsonForResult<List<MaterialApplyVo>> getList(@RequestBody MaterialApplyDto materialApplyDto) {
		List<MaterialApplyVo> list = materialApplyService.getList(materialApplyDto);
		Integer count = materialApplyService.getCount(materialApplyDto);
		return JsonForResult.<List<MaterialApplyVo>>builder()
				.data(list).total(count)
				.success(true).build();
	}

	/**
	 * 耗材申请详情
	 *
	 * @param id 耗材申请ID
	 * @return 耗材申请详情
	 */
	@ApiOperation("耗材申请详情")
	@ApiImplicitParam(name = "id", value = "耗材申请id", required = true, dataType = "String")
	@GetMapping("/getById/{id}")
	public JsonForResult<MaterialApplyVo> getById(@PathVariable String id) {
		MaterialApplyVo materialApplyVo = materialApplyService.getInfoById(id);
		return JsonForResult.<MaterialApplyVo>builder().data(materialApplyVo).success(true).build();
	}

	/**
	 * 删除耗材申请
	 *
	 * @param id 耗材申请ID
	 * @return
	 */
	@DeleteMapping("/remove/{id}")
	@ApiOperation("删除耗材申请")
	@ApiImplicitParam(name = "id", value = "耗材申请id", required = true, dataType = "String")
	public JsonForResult remove(@PathVariable String id) {
		materialApplyService.deleteByPrimaryKey(id);
		return JsonForResult.builder().success(true).build();
	}
}
